package com.example.jones.function;

import com.example.jones.test.R;
import com.example.util.HttpUtil;
import com.example.util.HttpUtilWithParameter;
import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class RegisterView {
	
	private Context mcontext = null;
	private View mView = null;
	private TextView username_reg, password_reg,password_repeat;
	private Button register ;
	
	public RegisterView(Context c) {
		this.mcontext = c;
	}

	public View getView() {
		mView = View.inflate(mcontext, R.layout.register, null);
		
		username_reg = (TextView) mView.findViewById(R.id.usernamereg);
		password_reg = (TextView) mView.findViewById(R.id.regpwd);
		password_repeat = (TextView) mView.findViewById(R.id.regpwd_repeat);

		register = (Button) mView.findViewById(R.id.register);
		
		
		register.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				String url = HttpUtil.Base_url+"/RegisterService";
				try {
					if(username_reg.getText().toString().equals("")||password_reg.getText().toString().equals("")
							||password_repeat.getText().toString().equals("")){
						Toast.makeText(mcontext, "请填写完整信息！", 1000).show();
						return;
					}else if(!password_reg.getText().toString().equals(password_repeat.getText().toString())){
						Toast.makeText(mcontext, "请重新确认密码！"+password_reg.getText().toString()+password_repeat.getText().toString(), 1000).show();
						return;
					}else{
						if(HttpUtilWithParameter.Register(url,username_reg.getText().toString(),
								password_reg.getText().toString())=="true"){
							Toast.makeText(mcontext, "注册成功！", 1000).show();
							}else{
								Toast.makeText(mcontext, "！", 1000).show();
								return;
								}
						};
						} catch (Exception e) {
							e.printStackTrace();
							}
				}
			});
		
		return mView;
		}
}
